# -*- coding:utf-8 -*-
# @Auther :shen
# @Time :2022/7/7 15:37
# @Function
import time

# 创建角色类
class Role():
    # 初始化角色的属性
    def __init__(self, name, sex, equipment, blood=100):
        self.name = name
        self.sex = sex
        self.blood = blood
        self.equipment = equipment
        self.room = None  # 是否加入房间，默认未加入

    # 进行角色的攻击行为，判断是否装配防弹衣
    def attack(self, other):
        print("普通攻击")
        if other.equipment == "yes":
            other.blood -= 5
        elif other.equipment == "no":
            other.blood -= 10

# 创建房间类
class Room():
    # 初始化房间信息，房间名，房间成员
    def __init__(self, name):
        self.name = name
        self.member_list = []  # 房间成员列表

    # 增加房间成员
    def add_member(self, role):
        if role.room == None:  # 判断角色是否加入房间
            if len(self.member_list) < 2:
                self.member_list.append(role)
                role.room = self
                print(f"{role.name}成功加入{self.name}房间")
                print(rooms[room_name].member_list[0])
        else:
            print(f"{role.name}已加入{role.room.name}房间")

# 创建角色，房间字典，存放信息方便调用
roles = dict()
rooms = dict()


def crete_role():
    # 创建角色函数
    name, sex, equipment = input("请输入角色的姓名与性别，是否装备防弹衣，{yes，no} 空格分隔：\n").split()
    roles[name] = Role(name, sex, equipment)


def crete_room():
    # 创建房间函数
    room = input("请输入房间的名字：\n")
    rooms[room] = Room(room)


while 1:
    print(
          "------------1.创建角色------------\n"
          "------------2.创建房间------------\n"
          "------------3.加入房间------------\n"
          "------------4.开始游戏------------\n"
          "------------5.退出游戏------------\n"
          )
    in_option = int(input("请输入选项："))
    if in_option == 1:
        crete_role()
    elif in_option == 2:
        crete_room()
        print(rooms)
    elif in_option == 3:
        print(f"当前角色有{roles.keys()}，当前房间有{rooms.keys()}")
        role_name, room_name = input("请输入您要加入的角色和房间名，空格分隔:\n").split()
        rooms[room_name].add_member(roles[role_name])
    elif in_option == 4:
        # 角色对战
        i = 1
        while 1:
            print("_" * 40)
            print(f"第----<{i}>----回合".center(33))
            i = i + 1
            # 角色A攻击
            print(f"{rooms[room_name].member_list[0].name}攻击方法——————》", end="")
            rooms[room_name].member_list[0].attack(rooms[room_name].member_list[1])

            # 判断血量，是否可以结束游戏
            if rooms[room_name].member_list[0].blood <= 0 or rooms[room_name].member_list[1].blood <= 0:
                # 输出双方的血量
                print(f"{rooms[room_name].member_list[0].name}:hp--{rooms[room_name].member_list[0].blood}    vs   {rooms[room_name].member_list[1].name}:hp--{rooms[room_name].member_list[1].blood}")
                winner = rooms[room_name].member_list[0].name if rooms[room_name].member_list[0].blood > 0 else rooms[room_name].member_list[1].name
                print(f"{winner}---Win".center(40, "_"))
                break

            # 角色B攻击
            print(f"{rooms[room_name].member_list[1].name}攻击方法——————》", end="")
            rooms[room_name].member_list[1].attack(rooms[room_name].member_list[0])

            # 判断血量，是否可以结束游戏
            if rooms[room_name].member_list[0].blood <= 0 or rooms[room_name].member_list[1].blood <= 0:
                # 输出双方的血量
                print(f"{rooms[room_name].member_list[0].name}:hp--{rooms[room_name].member_list[0].blood}    vs   {rooms[room_name].member_list[1].name}:hp--{rooms[room_name].member_list[1].blood}")
                winner = rooms[room_name].member_list[0].name if rooms[room_name].member_list[0].blood > 0 else rooms[room_name].member_list[1].name
                print(f"{winner}---Win".center(40, "_"))
                break

            time.sleep(1)
            print("_" * 40)
    elif in_option == 5:
        break
    else:
        print("输入错误！请输入1-5选择操作！")




